package edu.calpoly.android.echoes;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

public class DatabaseInterlace {
	
	ShapeDBAdapter m_shapeDB;
	private Context m_context;
	
	public DatabaseInterlace(Context context, ShapeDBAdapter db) {
		m_context = context;
		m_shapeDB = db;
		m_shapeDB.open();
	}
	
	public boolean saveGame(ArrayList<MyDrawableShapes> mDS) {
		
		long gameID = m_shapeDB.currGame();
		Log.e("DatabaseI", "long: " + gameID);
		String gName = m_shapeDB.gameName();
		
		m_shapeDB.removeGame(gameID);
		m_shapeDB.newGame(gName);
    	for(MyDrawableShapes shape : mDS) {
    		long _id = m_shapeDB.insertShape(shape);
    		if(_id == -1)
    			return false;
    	}
    	Toast toast = Toast.makeText(m_context, "Game Saved", Toast.LENGTH_SHORT);
    	toast.show();
    	return true;
    }
	
	public ArrayList<MyDrawableShapes> loadGame() {
		return m_shapeDB.getAllShapes();
	}

}
